package neusoft.yuejian_11.model;

import java.util.List;

import neusoft.yuejian_11.base.BaseActivity;
import neusoft.yuejian_11.bean.AttentionBean;
import neusoft.yuejian_11.bean.ClubCollectBean;
import neusoft.yuejian_11.bean.IsAttentionBean;
import neusoft.yuejian_11.bean.MasterCollectBean;
import neusoft.yuejian_11.bean.PostCollectBean;
import neusoft.yuejian_11.bean.TrainCollectBean;
import neusoft.yuejian_11.interF.AttentionService;
import neusoft.yuejian_11.interF.Const;
import neusoft.yuejian_11.listener.RetrofitListener;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by NEUSOFT on 2017/10/17.
 */

public class AttentionModel extends BaseActivity{
    private Retrofit retrofit;
    public AttentionModel(){
        retrofit  = new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    //判断俱乐部是否收藏
    public void isCollectedClub(String u_id, String select_id, String flag,final RetrofitListener listener) {
        AttentionService attentionService = retrofit.create(AttentionService.class);
        Call call=attentionService.isCollected(String.valueOf(u_id),String.valueOf(select_id), "4");
        call.enqueue(new Callback<IsAttentionBean>() {
            @Override
            public void onResponse(Call<IsAttentionBean> call, Response<IsAttentionBean> response) {
                IsAttentionBean isAttentionBean=response.body();
                listener.onSuccess(isAttentionBean,3);
            }
            @Override
            public void onFailure(Call<IsAttentionBean> call, Throwable t) {

            }
        });
    }
    //判断培训是否收藏
    public void isCollectedTrain(String u_id, String select_id, String flag,final RetrofitListener listener) {
        AttentionService attentionService = retrofit.create(AttentionService.class);
        Call call=attentionService.isCollected(String.valueOf(u_id),String.valueOf(select_id), "0");
        call.enqueue(new Callback<IsAttentionBean>() {
            @Override
            public void onResponse(Call<IsAttentionBean> call, Response<IsAttentionBean> response) {
                IsAttentionBean isAttentionBean=response.body();
                listener.onSuccess(isAttentionBean,3);
            }
            @Override
            public void onFailure(Call<IsAttentionBean> call, Throwable t) {

            }
        });
    }





    //判断晒图是否收藏
    public void isCollected(String u_id, String select_id, String flag,final RetrofitListener listener) {
        AttentionService attentionService = retrofit.create(AttentionService.class);
        Call call=attentionService.isCollected(String.valueOf(u_id),String.valueOf(select_id), "5");
        call.enqueue(new Callback<IsAttentionBean>() {
            @Override
            public void onResponse(Call<IsAttentionBean> call, Response<IsAttentionBean> response) {
                IsAttentionBean isAttentionBean=response.body();
                listener.onSuccess(isAttentionBean,3);
            }
            @Override
            public void onFailure(Call<IsAttentionBean> call, Throwable t) {

            }
        });
    }

    //判断晒图是否收藏
    public void isCollectedM(String u_id, String select_id, String flag,final RetrofitListener listener) {
        AttentionService attentionService = retrofit.create(AttentionService.class);
        Call call=attentionService.isCollected(String.valueOf(u_id),String.valueOf(select_id), "3");
        call.enqueue(new Callback<IsAttentionBean>() {
            @Override
            public void onResponse(Call<IsAttentionBean> call, Response<IsAttentionBean> response) {
                IsAttentionBean isAttentionBean=response.body();
                listener.onSuccess(isAttentionBean,3);
            }
            @Override
            public void onFailure(Call<IsAttentionBean> call, Throwable t) {

            }
        });
    }


    //用户收藏帖子
    public void userCollectPost(String u_id, String p_id,final RetrofitListener listener) {
        AttentionService attentionService=retrofit.create(AttentionService.class);
        Call call = attentionService.userCollectPost(u_id,p_id);
        call.enqueue(new Callback<AttentionBean>() {
            @Override
            public void onResponse(Call<AttentionBean> call, Response<AttentionBean> response) {
                AttentionBean attentionBean=response.body();
                listener.onSuccess(attentionBean,4);
            }
            @Override
            public void onFailure(Call<AttentionBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }



    //用户收藏大师
    public void userCollectMaster(String u_id, String pm_id,final RetrofitListener listener) {
        AttentionService attentionService=retrofit.create(AttentionService.class);
        Call call = attentionService.userCollectMaster(u_id,pm_id);
        call.enqueue(new Callback<AttentionBean>() {
            @Override
            public void onResponse(Call<AttentionBean> call, Response<AttentionBean> response) {
                AttentionBean attentionBean=response.body();
                listener.onSuccess(attentionBean,4);
            }
            @Override
            public void onFailure(Call<AttentionBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }

    //获取我收藏的俱乐部列表
    public void getClubCollectlist(int u_id, String flag,final RetrofitListener listener) {
        AttentionService attentionService = retrofit.create(AttentionService.class);
        Call<List<ClubCollectBean>> call=attentionService.getClubCollectlist(getU_id(),"4");
        call.enqueue(new Callback<List<ClubCollectBean>>() {
            @Override
            public void onResponse(Call<List<ClubCollectBean>> call, Response<List<ClubCollectBean>> response) {
                List<ClubCollectBean> clubCollectBean = response.body();
                listener.onSuccess(clubCollectBean, 2);
            }
            @Override
            public void onFailure(Call<List<ClubCollectBean>> call, Throwable t) {
            }
        });
    }

    //获取我收藏的帖子列表
    public void getPostCollectlist(int u_id, String flag,final RetrofitListener listener) {
        AttentionService attentionService = retrofit.create(AttentionService.class);
        Call<List<PostCollectBean>> call=attentionService.getPostCollectlist(getU_id(),"5");
        call.enqueue(new Callback<List<PostCollectBean>>() {
            @Override
            public void onResponse(Call<List<PostCollectBean>> call, Response<List<PostCollectBean>> response) {
                List<PostCollectBean> postCollectBean = response.body();
                listener.onSuccess(postCollectBean, 1);
            }
            @Override
            public void onFailure(Call<List<PostCollectBean>> call, Throwable t) {
            }
        });
    }



    //获取我收藏的培训列表
    public void getTrainCollectlist(int u_id, String flag,final RetrofitListener listener) {
        AttentionService attentionService = retrofit.create(AttentionService.class);
        Call<List<TrainCollectBean>> call=attentionService.getTrainCollectlist(getU_id(),"0");
        call.enqueue(new Callback<List<TrainCollectBean>>() {
            @Override
            public void onResponse(Call<List<TrainCollectBean>> call, Response<List<TrainCollectBean>> response) {
                List<TrainCollectBean> trainCollectBean = response.body();
                listener.onSuccess(trainCollectBean, 1);
            }
            @Override
            public void onFailure(Call<List<TrainCollectBean>> call, Throwable t) {
            }
        });
    }




    //获取我收藏的大师列表
    public void getMasterCollectlist(int u_id, String flag,final RetrofitListener listener) {
        AttentionService attentionService = retrofit.create(AttentionService.class);
        Call<List<MasterCollectBean>> call=attentionService.getMasterCollectlist(getU_id(),"3");
        call.enqueue(new Callback<List<MasterCollectBean>>() {
            @Override
            public void onResponse(Call<List<MasterCollectBean>> call, Response<List<MasterCollectBean>> response) {
                List<MasterCollectBean> masterCollectBean = response.body();
                listener.onSuccess(masterCollectBean, 1);
            }
            @Override
            public void onFailure(Call<List<MasterCollectBean>> call, Throwable t) {
            }
        });
    }

}
